/**
 * Copyright 2022-2023 SpriteLab @ Northeastern University
 *
 * This file is part of 5GSniffer.
 *
 * 5GSniffer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * 5GSniffer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * A copy of the GNU Affero General Public License can be found in
 * the LICENSE file in the top-level directory of this distribution
 * and at http://www.gnu.org/licenses/.
 *
 */

#include "gtest/gtest.h"
#include "dmrs.h"
#include "fftw3.h"
// #include "mat.h"

class dmrs_test : public ::testing::Test {
 protected:
  dmrs_test() {
  }

};

TEST_F(dmrs_test, test_pbch_dmrs_sequence_generation) {

dmrs dmrs1;

uint8_t i_ssb = 0;
uint16_t nid_cell = 0;
uint8_t n_hf = 0;

std::vector<uint8_t> pbch_dmrs_0_0_0 = dmrs1.generate_pbch_dmrs_seq(i_ssb, n_hf, nid_cell);

std::vector<uint8_t> pbch_dmrs_ref_0_0_0 = {0,0,0,0,1,1,1,0,1,1,1,0,0,1,1,0,1,1,1,0,1,1,0,1,0,1,1,1,1,0,0,0,1,0,1,0,0,1,1,1,1,0,1,1,0,1,1,1,0,0,0,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,1,0,1,1,0,1,1,0,0,0,0,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,0,1,1,0,0,0,0,0,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,0,0,0,1,0,1,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,1,0,1,0,0,1,1,1,0,1,0,1,1,1,0,0,0,0,1,0,1,1,1,1,0,0,1,0,1,1,1,0,1,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,1,0,0,0,1,1,0,0,0,1,0,1,0,1,1,1,0,0,1,0,1,1,0,1,0,1,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,0,1,1,1,0,1,1,0,1,1,1,0,1,0,1,1,0,1,1,1,1,0,0,1,1,0,1,1,0,1,0,1,1,0,1,0,0,0,1,1,1,1,0,1,0,1,0};

for (int i = 0; i < pbch_dmrs_0_0_0.size(); ++i) {
  EXPECT_EQ((pbch_dmrs_0_0_0.at(i)), (pbch_dmrs_ref_0_0_0.at(i))) << "Vectors x and y differ at index " << i;
}

}


TEST_F(dmrs_test, test_pbch_dmrs_symbol_generation) {

dmrs dmrs1;

uint8_t i_ssb = 0;
uint16_t nid_cell = 0;
uint8_t n_hf = 0;

std::vector<std::complex<float>> pbch_dmrs_symb_0_0_0 = dmrs1.generate_pbch_dmrs_symb(i_ssb, n_hf, nid_cell);

std::vector<std::complex<float>> pbch_dmrs_symb_ref_0_0_0 = {0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,0.707106781186548 - 0.707106781186548i,0.707106781186548 + 0.707106781186548i,0.707106781186548 - 0.707106781186548i,-0.707106781186548 - 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i,-0.707106781186548 + 0.707106781186548i};


for (int i = 0; i < pbch_dmrs_symb_0_0_0.size(); ++i) {
  EXPECT_EQ((pbch_dmrs_symb_0_0_0.at(i)).real(), (pbch_dmrs_symb_ref_0_0_0.at(i)).real()) << "Vectors x and y differ at real part index " << i;
  EXPECT_EQ((pbch_dmrs_symb_0_0_0.at(i).imag()), (pbch_dmrs_symb_ref_0_0_0.at(i)).imag()) << "Vectors x and y differ at imag part index " << i;
}

}

